// Created by Joe on 2017/7/10.

app.controller(
    'ExitEntryController',
    [
        'KEY', 'config', '$scope', '$location', '$filter', 'UserService', 'ExitEntryService',
        function (KEY, config, $scope, $location, $filter, UserService, ExitEntryService) {
            init();

            function init() {
                // set panel
                $scope.panel = {load: false};

                // set data
                $scope.data = {
                    num: {},
                    updateTime: ''
                };

                // get info
                $scope.panel.load = true;
                ExitEntryService.getExitEntryInfo()
                    .then(function (info) {
                        $scope.data.num = info.num;
                        $scope.data.updateTime = $filter('mul_date')(info.updateTime, 1);

                        $scope.panel.load = false;
                    });

                // global action
                document.addEventListener('keydown', globalAction);
            }

            function globalAction() {
                if (event.keyCode === KEY.BACK) {
                    event.preventDefault();
                    $scope.$apply(function () {
                        $location.path('/home').replace();
                    });
                }
            }

            $scope.$on('$destroy', function () {
                document.removeEventListener('keydown', globalAction);
            });
        }
    ]
);